﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <meta http-equiv="content-type" content="txt/html charset=utf-8" />
    <title>Windows服务管理</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
   
</head>
<body>
    <div class="panelSection">    
        <div class="easyui-panel " title="操作区域" style="padding:3px;" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
             <div style="margin: 3px 0px 3px 3px">
                <div style="float: left; margin-left: 0px">
                    <span class="" style="margin-bottom: 5px">
                        筛选：</span> 
                    <input type="text" id="txtFilter" />
                </div>
             </div>
        </div>
    </div>
    <div class="panelSection">    
        <div class="easyui-panel " title="windows服务" style="padding:3px;width:100%" 
        data-options="closable:false,collapsible:true,minimizable:false,maximizable:false"> 
               <div style="margin: 3px 0px 3px 3px">
                <table id="gdWindows" class="easyui-datagrid" style="width: 100%; height: 500"
                        data-options="rownumbers:true,pagination:false,striped:false,checkOnSelect:true,selectOnCheck:true,
                        singleSelect:false,multiSort:true,remoteSort:false,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                    
                </table>  
            </div>

        </div> 

    </div> 
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script> 
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    /*
    创建人：Wangjh
    日期：2024-12-19
    描述：windows服务管理
    */
    var page = {
        pagetotal: 0,
        pageSize: 50,
        pageNumber: 1,
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/BrowseFilesManagerHandler.ashx",
        serviceList: [],
        //初始化页面
        init: function () {
            page.bind();
            page.getWindowsServiceList();
            //customizedEasyuiPagination('pp'); //定制化分页
        },
        //页面事件绑定
        bind: function () {
            $('#txtFilter').on('keyup', function (event) {
                var keyCode = event.keyCode || event.which;
                var val = $("#txtFilter").val();
                if (isNullOrWhiteSpaceStr(val)) {
                    $("#gdWindows").datagrid('loadData', { total: page.serviceList.length, rows: page.serviceList });
                    return;
                }
                if ((keyCode >= 65 && keyCode <= 90) || (keyCode >= 97 && keyCode <= 122)) {
                    page.filterService(val);
                }
            });
            $("#gdWindows").datagrid({
                columns: [[
                    { field: 'ck', title: '选择', checkbox: true },
                    { field: 'DisplayName', title: '服务名称', sortable: true, formatter: function (value, row, index) {
                        return '<span style="background-position-x:left;display:inline-block;padding-left:20px;height:20px;line-height:16px" class="icon-metro-cog">' + value + '</span>';

                    }
                    },
                     { field: 'ServiceName', title: 'ServiceName', sortable: true, hidden: false },
                    { field: 'Status', title: '状态', width: 130, sortable: true, formatter: function (value, row, index) {
                        if (value == 4) {
                            return "已启动";
                        } else {
                            return "";
                        }
                    }
                    },
                    { field: 'OPERATE', title: '操作', width: 130, formatter: function (value, row, index) {

                        var name = encodeURIComponent(row.ServiceName);

                        var btnHtml = "<a   class='' onclick=page.startService('" + name + "') style='color:blue;cursor:pointer;width: 40px; height: 22px'>启动</a>";

                        btnHtml += "<a class=''  onclick=page.stopService('" + name + "') style='color:blue;margin-left:30px;cursor:pointer;width: 40px; height: 22px'>停止</a>";

                        return btnHtml;
                    }
                    }
                ]]
            })
        },
        filterService: function (val) {
            if (isNullOrWhiteSpaceStr(val))
                return;
            //筛选serviceList的数据进行首段匹配重新绑定到表格
            var lists = page.serviceList.filter(function (item) {
                if (item.DisplayName.toLowerCase().startsWith(val.toLowerCase())) {
                    return item;
                }
            });
            $("#gdWindows").datagrid('loadData', { total: lists.length, rows: lists });
        },
        startService: function (serviceName) {
            var param = {
                action: "startService",
                serviceName: decodeURIComponent(serviceName)
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    //console.log(data);

                    var result = JSON.parse(data);
                    if (result.Result) {//处理成功后刷新列表
                        page.getWindowsServiceList();
                    }
                    displayMessage(result.Message, result.Result);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        stopService: function (serviceName) {
            var param = {
                action: "stopService",
                serviceName: decodeURIComponent(serviceName)
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $.messager.progress({ text: '', msg: '处理中...' });
                },
                success: function (data) {
                    $.messager.progress('close');
                    //console.log(data);

                    var result = JSON.parse(data);
                    if (result.Result) {//处理成功后刷新列表
                        page.getWindowsServiceList();
                    }
                    displayMessage(result.Message, result.Result);
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $.messager.progress('close');
                    alert(XMLHttpRequest.responseText);
                }
            });
        },
        getWindowsServiceList: function () {
            var param = {
                action: "getWindowsServiceList"
            };
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $('#gdWindows').datagrid('loading');
                },
                success: function (data) {
                    $('#gdWindows').datagrid('loaded');
                    //console.log(data);

                    var result = JSON.parse(data);
                    if (result.Result) {
                        var dt = result.ReturnData;
                        page.serviceList = dt;
                        //console.log(dt);
                        $("#gdWindows").datagrid('loadData', { total: dt.length, rows: dt });
                        page.filterService($("#txtFilter").val());
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $('#gdWindows').datagrid('loaded');
                    alert(XMLHttpRequest.responseText);
                }
            });
    
        },
        //清除方法，重要！！！
        reset: function (iscondition, isresult) {
            //clearMessage();

        }
    }
    $(function () {
        page.init();
    });
</script>